@extends('home.layout')

@section('header_class', 'site-header')

@section('content')
    <section class="layui-col-md8">
        @if (!empty($search))
            <div class="search-header">
                <h1>“{{ $search }}”搜索到{{ $count }}个结果</h1>
            </div>
        @endif
        @if ($articles)
            @foreach ($articles as $article)
                <article class="post">
                    <div class="post-container">
                        <div class="post-header">
                            <h2 class="post-title">
                                <a href="{{ $article->url }}">{{ $article->title }}</a>
                            </h2>
                            <div class="post-byline">
                                发布于
                                <a class="date" href="{{ date('/Y/m', $article->published_at) }}">{{ date('Y年n月j日', $article->published_at) }}</a>
                            </div>
                        </div>
                        <div class="post-content">
                            {!! $article->excerpt !!}
                            <div class="post-categories">
                                <span>分类至</span>
                                <a href="/category/{{ $article->category->alias }}">{{ $article->category->name }}</a>，
                            </div>
                            <span class="comment-link">
                                含
                                <a href="{{ $article->url }}#comments">{{ $article->comments_count }}条评论</a>
                            </span>
                        </div>
                    </div>
                </article>
            @endforeach
            <nav class="pagination">{!! $pageHtml !!}</nav>
        @else
            <article class="post">
                <div class="post-container" style="text-align:center">
                    <i class="layui-icon layui-icon-face-surprised" style="font-size:100px"></i>
                    <p style="font-size:1.5em;font-weight:700;margin-bottom:2em">暂无数据</p>
                </div>
            </article>
        @endif
    </section>
    <aside class="layui-col-md4">
        <section class="widget widget-profile">
            <div class="profile">
                <div class="profile-picture"><img class="avatar" src="{{ $setting->master_avatar }}" width="50" height="50"></div>
                <div class="profile-intro">
                    <span class="name">{{ $setting->master_name }}</span>
                    <p class="intro">{{ $setting->master_intro }}</p>
                </div>
            </div>
        </section>
        <section class="widget widget-search">
            <form action="/">
                <input type="search" name="s" class="layui-input" placeholder="输入关键词" required value="{{ $search ?? '' }}"/>
                <button type="submit" class="layui-btn layui-btn-primary">搜索</button>
            </form>
        </section>
        <section class="widget">
            <h2 class="widget-title">最新评论</h2>
            <ul>
                @foreach ($newComments as $comment)
                    <li>
                        <a href="{{ $comment->article->url }}#comment-{{ $comment->id }}">{{ $comment->name }}
                            评论了 {{ $comment->article->title }}</a>
                    </li>
                @endforeach
            </ul>
        </section>
        <section class="widget">
            <h2 class="widget-title">阅读排行</h2>
            <ul>
                @foreach ($readArticles as $article)
                    <li>
                        <a href="{{ $article->url }}">{{ $article->title }}</a>
                    </li>
                @endforeach
            </ul>
        </section>
        <section class="widget widget-categories">
            <h2 class="widget-title">文章分类</h2>
            <ul>
                @foreach ($categories as $category)
                    <li>
                        <a href="/category/{{ $category['alias'] }}">{{ $category['name'] }}</a>
                        <span class="layui-badge layui-bg-gray">({{ $category['articles_count'] }})</span>
                    </li>
                @endforeach
            </ul>
        </section>
        <section class="widget widget-categories">
            <h2 class="widget-title">文章归档</h2>
            <ul>
                @foreach ($archiveGroups as $archive)
                    <li>
                        <a href="{{ $archive->archive_url }}">{{ date('Y年n月', $archive->month_time) }}</a>
                        <span class="layui-badge layui-bg-gray">({{ $archive->num }})</span>
                    </li>
                @endforeach
            </ul>
        </section>
        @if (isset($isHome) && !empty($links))
            <section class="widget">
                <h2 class="widget-title">友情链接</h2>
                <ul>
                    @foreach ($links as $link)
                        <li><a href="{{ $link['link_url'] }}" target="_blank">{{ $link['link_name'] }}</a></li>
                    @endforeach
                </ul>
            </section>
        @endif
    </aside>
@endsection
